﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UControl_Newslist : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptdatabind();
        }
    }

    private void rptdatabind()
    {
        YqhData obj = new YqhData();
        string sql = string.Format(@"select top 8 nid,ndate=CONVERT(VARCHAR(23),ndate,111),nsubject
                                    from news inner join newstype on news.ntypeid = newstype.tid 
                                    where tname = '{0}'
                                    order by ndate desc", Subject.ToString());
        rptnewslist.DataSource = obj.FillDataSet(sql);
        rptnewslist.DataBind();
    }

    /// <summary>
    /// 新闻标题
    /// </summary>
    private string _Subject;
    public string Subject
    {
        get { return _Subject; }
        set { _Subject = value; }
    }
    protected void rptnewslist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
            case "check":
                Response.Redirect(string.Format("shownews.aspx?op=news&id={0}",e.CommandArgument));
                break;
        }
    }
    protected void btnmore_Click(object sender, EventArgs e)
    {
        YqhData obj = new YqhData();
        DataSet ds;
        ds = obj.FillDataSet(string.Format(@"select top 1 ntypeid from news inner join newstype on tid=ntypeid
where tname='{0}'",Subject));
        int t = Convert.ToInt32(ds.Tables[0].Rows[0]["ntypeid"].ToString());
        Response.Redirect(string.Format("newstype.aspx?op=type&tid={0}",t));
    }
}
